package com.example.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jms.annotation.JmsListener;
import org.springframework.jms.config.JmsListenerContainerFactory;
import org.springframework.stereotype.Component;

import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.Session;
import javax.jms.TextMessage;

/**
 * @ClassName QueueListner
 * @Description
 * @Author Jingxiao.Ye
 * @Date 2022/1/30 下午4:37
 * @Version V1.0
 * @Since JDK 11
 */
@Component
public class QueueListener {

    @JmsListener(destination = "queue-test")
    public void onQueueMessage(String message){
        System.out.println(message);
    }

    @JmsListener(destination = "topic-test",concurrency = "1", containerFactory = "jmsListenerContainerTopicFactory")
    public void onTopicMessage(Message message, Session session) throws JMSException {
        message.acknowledge();
        TextMessage textMessage = (TextMessage) message;
        System.out.println(textMessage.getText());
    }
}
